#include <algorithm>
#include <iostream>
#include <string>

#include "HttpServer.h"

#define WWWROOT "./wwwroot/"

using namespace std;

std::string RequestStr(const Request& request) {
    std::string req_str;
    req_str = request.method_ + " " + request.url_ + " " + request.version_ + "\r\n";
    for (auto& kv : request.kvs_) {
        std::string head = kv.first + ": " + kv.second + "\r\n";
        req_str += head;
    }
    req_str += "\r\n";
    req_str += request.body_;
    return req_str;
}

void Login(const Request& req, Response* rsp) {
    rsp->SetContent(RequestStr(req), "text/plain");
    rsp->status_code_ = "200";
    rsp->describe_ = "OK";
}

int main() {
    EventLoop loop;
    HttpServer httpserver(&loop, "HttpServer");
    httpserver.SetRootDir(WWWROOT);
    httpserver.Post("/login", Login);

    httpserver.start();
    loop.Loop();
    return 0;
}